//
//  RoadDownView.m
//  TT
//
//  Created by Lenny on 16/4/18.
//  Copyright © 2016年 Lenny. All rights reserved.
//

#import "RoadDownV.h"

@interface RoadDownV ()

@property(nonatomic,copy)void(^eventBlock)(UIButton *btn);

@end

@implementation RoadDownV

#pragma mark - public motheds

- (void)addUI {
    
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = @"路途信息";
    nameLabel.font = [UIFont systemFontOfSize:15];
    [self addSubview:nameLabel];
    
    NSDictionary *twoDic = @{NSForegroundColorAttributeName:WL_S_Bar_N_Color,NSFontAttributeName:[UIFont systemFontOfSize:13]};
    NSMutableDictionary *oneDic = [NSMutableDictionary dictionaryWithDictionary:@{NSForegroundColorAttributeName:[UIColor colorWithHexColor:@"57b988"],NSFontAttributeName:[UIFont systemFontOfSize:13]}];
    
    UIButton *btn1 = [[UIButton alloc] init];
    [btn1 setButtonStyleWithBtnStr:@"最快路线\n32分钟"
                        withOneDic:oneDic
                        withTwoDic:twoDic];
    btn1.layer.borderColor = WL_S_Frame_Color.CGColor;
    btn1.layer.borderWidth = 1;
    [self addSubview:btn1];
    
    oneDic[NSForegroundColorAttributeName] = [UIColor colorWithHexColor:@"ec5433"];
    UIButton *btn2 = [[UIButton alloc] init];
    [btn2 setButtonStyleWithBtnStr:@"平均时长\n80km/h"
                        withOneDic:oneDic
                        withTwoDic:twoDic];
    btn2.layer.borderColor = WL_S_Frame_Color.CGColor;
    btn2.layer.borderWidth = 1;
    [self addSubview:btn2];
    
    oneDic[NSForegroundColorAttributeName] = [UIColor colorWithHexColor:@"ae7a31"];
    UIButton *btn3 = [[UIButton alloc] init];
    [btn3 setButtonStyleWithBtnStr:@"最近路线\n20km"
                        withOneDic:oneDic
                        withTwoDic:twoDic];
    btn3.layer.borderColor = WL_S_Frame_Color.CGColor;
    btn3.layer.borderWidth = 1;
    [self addSubview:btn3];
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"品味路途" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    btn.backgroundColor = WL_Top_Color;
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:btn];
    
    __weak typeof(self) weakSelf = self;
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(weakSelf);
        make.top.mas_equalTo(3);
    }];
    
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(weakSelf);
        make.top.equalTo(nameLabel.mas_bottom).offset(3);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(100);
    }];
    
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(btn1.mas_left).offset(-20);
        make.top.equalTo(btn1);
        make.size.equalTo(btn1);
    }];
    
    [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(btn1.mas_right).offset(20);
        make.top.equalTo(btn1);
        make.size.equalTo(btn1);
    }];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(weakSelf);
        make.bottom.mas_equalTo(-5);
        make.top.equalTo(btn1.mas_bottom).offset(5);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(150);
    }];
    
    btn1.tag = 1;
    btn2.tag = 2;
    btn3.tag = 3;
    btn.tag = 4;
    
    [btn1 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [btn2 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [btn3 addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)addEvent:(void (^)(UIButton *))eventBlock {
    
    self.eventBlock = eventBlock;
}


#pragma mark - event methods

- (void)btnAction:(UIButton *)sender {
    
    if (self.eventBlock) self.eventBlock(sender);
}

@end
